home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / amicad / arexx_english / addrefs.amicad next >
Text File  |  1998-08-09  |  4KB  |  160 lines

  1. /* This script adds references to the selected parts or to all the specified components
  2.    © R.Florac, Chez Corbin, 4 juin 1998, v1.00
  3.    $VER: AddRefs.AmiCAD 1.01e (© R.Florac, 9 août 1998) */
  4.  
  5. options results
  6.  
  7. signal on error
  8. signal on syntax
  9.  
  10. 'SELECT("Component type to reference"+CHR(10)+"Resistances"+CHR(10)+"Capacitors"+CHR(10)+"Diodes"+CHR(10)+"Transistors"+CHR(10)+"Integrated circuits"+CHR(10)+"Specific Components")'
  11. choix=result
  12. select
  13.     when choix=1 then do
  14.     reference='R'
  15.     type="#?Resist#?"
  16.     end
  17.     when choix=2 then do
  18.     reference='C'
  19.     type="#?Capacit#?"
  20.     end
  21.     when choix=3 then do
  22.     reference='D'
  23.     type="#?Diod#?"
  24.     end
  25.     when choix=4 then do
  26.     reference='Q'
  27.     type="#?Transist#?"
  28.     end
  29.     when choix=5 then do
  30.     reference="IC"
  31.     type=1
  32.     'DEF TEST_CIRCUIT(N)=IF((TYPE(N)==1) & (TEST(N)==1),1,0)'
  33.     end
  34.     when choix=6 then do
  35.     'ASK("What is the name of"+CHR(10)+"the components to reference?"+CHR(10)+"You can use the generic"+CHR(10)+"chars (#?) for a"+CHR(10)+"larger selection")'
  36.     type=result
  37.     if type='' then exit
  38.     'ASK("What is the reference"+CHR(10)+"for these components?")'
  39.     reference=result
  40.     if reference='' then exit
  41.     end
  42.     otherwise exit
  43. end
  44. 'N=FIRSTSEL'; obj=result
  45. if type=1 then do
  46.     if obj=0 then do
  47.     'MESSAGE("Mark the devices"+CHR(10)+"to reference, even the"+CHR(10)+"devices that are allready"+CHR(10)+"referenced before"+CHR(10)+"calling this script")'
  48.     exit
  49.     end
  50.     choix=1
  51. end
  52. else do
  53.     if obj>0 then do
  54.     'REQUEST("Do you want to reference"+CHR(10)+"only the selected"+CHR(10)+"components?"+CHR(10)+"If you choose NO the"+CHR(10)+"operation will be done"+CHR(10)+"for every component"+CHR(10)+"on the document.")'
  55.     choix=result
  56.     end
  57.     else choix=0
  58. end
  59.  
  60. if choix=0 then do
  61.     'N=FIRSTSEL:WHILE(N>0,UNMARK(N),N=NEXTSEL(N))'
  62.     'SECURITY(OBJECTS(-1)+10):N=0:I=0:WHILE(I=IF(I+1<=OBJECTS(-1),FINDPART(I+1,"'type'"),0),MARK(I):N=N+1):N'
  63.     n=result
  64. end
  65. else do
  66.     if type=1 then do
  67.     'SECURITY(OBJECTS(-1)+10):I=0:N=FIRSTSEL:WHILE(N,IF(TYPE(N)==1,I=I+1,UNMARK(N)),N=NEXTSEL(N)):I'
  68.     end
  69.     else 'SECURITY(OBJECTS(-1)+10):I=0:WHILE(N,N=FINDPART(N,"'type'"):IF(N>0,IF(TEST(N)>0,I=I+1,0):N=N+1,0)):I'
  70.     n=result
  71. end
  72. if n=0 then do
  73.     'MESSAGE("There is no"+CHR(10)+"object of this type")'
  74.     exit
  75. end
  76.  
  77. 'SAVEALL(-1)'
  78. call test_references(type,reference)
  79. objet=selection_objet(1,type)
  80. do i=1 to n
  81.     'GETREF('objet')'; ref=result
  82.     if ref=0 then call ajouter_reference(objet,reference)
  83.     else do
  84.     'READTEXT('ref')'
  85.     j=right(result,length(result)-length(reference))
  86.     if j~="" then do
  87.         ref.i=1
  88.     end
  89.     end
  90.     if i<n then objet=selection_objet(objet+1,type)
  91. end
  92.  
  93. objet=selection_objet(1,type)
  94. numref=0
  95. do i=1 to n
  96.     if ref.i~=1 then do
  97.     numref=numref+1
  98.     do while val.numref=1
  99.         numref=numref+1
  100.     end
  101.     'R=GETREF('objet'):SETTEXT(R,READTEXT(R)+"'numref'")'
  102.     end
  103.     if i<n then do
  104.     objet=selection_objet(objet+1,type)
  105.     end
  106. end
  107.  
  108. exit
  109.  
  110. ajouter_reference: procedure
  111.     parse arg obj,reference
  112.     'LINKREF('obj',WRITE("'reference'",COL('obj')+WIDTH('obj')+5,LINE('obj')+HEIGHT('obj')/2))'
  113.     return
  114. end
  115.  
  116. selection_objet: procedure
  117.     parse arg obj,type
  118.     if type=1 then do
  119.     'R='obj':WHILE(TEST_CIRCUIT(R)==0,R=NEXTSEL(R)):R'
  120.     end
  121.     else do
  122.     'R=FINDPART('obj',"'type'"):WHILE(TEST(R)==0,R=FINDPART(R+1,"'type'")):R'
  123.     end
  124.     return result
  125. end
  126.  
  127. test_references: procedure expose val.
  128.     parse arg type,reference
  129.     obj=1
  130.     'OBJECTS(-1)';objets=result
  131.     do while obj<=objets
  132.     if type=1 then do
  133.         'RO='obj':WHILE(IF(RO>0,TYPE(RO)<>1,0),RO=NEXTSEL(RO)):RO'; obj=result
  134.     end
  135.     else do
  136.         'FINDPART('obj',"'type'")'; obj=result
  137.     end
  138.     if obj=0 then leave
  139.     'GETREF('obj')'; ref=result
  140.     if ref>0 then do
  141.         'READTEXT('ref')'
  142.         j=right(result,length(result)-length(reference))
  143.         if j~="" then do
  144.         val.j=1
  145.         end
  146.     end
  147.     obj=obj+1
  148.     end
  149.     return
  150. end
  151.  
  152. syntax:
  153. erreur=RC
  154. 'MESSAGE("Script AddRefs"+CHR(10)+"Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  155. exit
  156.  
  157. error:
  158. 'MESSAGE("Script AddRefs"+CHR(10)+"Error in line 'SIGL'")'
  159. exit
  160.